import React, { FC } from 'react';
import User from './User';
import type { IProps } from './User';

function HOC(WrappedComponent: typeof User): FC<IProps> {
  let inputElement: any = null;

  function handleClick() {
    inputElement.focus();
  }

  function wrappedComponentStaic() {
    WrappedComponent.sayHello();
  }

  return (props: IProps) => (
    <div>
      <WrappedComponent
        inputRef={(el: any) => {
          inputElement = el;
        }}
        {...props}
      />
      <input type="button" value="获取子组件输入框焦点" onClick={handleClick} />
      <input type="button" value="调用子组件static" onClick={wrappedComponentStaic} />
    </div>
  );
}

export default HOC;
